from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)

# 模拟的用户数据
users = {
    'teacher': {'username': 'teacher1', 'password': 'pass123'},
    'student': {'username': 'student1', 'password': 'pass123'},
    'parent': {'username': 'parent1', 'password': 'pass123'},
}

# 登陆页面
@app.route('/', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        user_type = request.form['user_type']
        username = request.form['username']
        password = request.form['password']

        # 验证用户名和密码
        if username == users[user_type]['username'] and password == users[user_type]['password']:
            return redirect(url_for(f'{user_type}_dashboard'))
        else:
            return "登录失败，用户名或密码错误！"

    return render_template('login.html')

# 学生页面
@app.route('/student_dashboard')
def student_dashboard():
    return render_template('student_dashboard.html')

# 老师页面
@app.route('/teacher_dashboard')
def teacher_dashboard():
    return render_template('teacher_dashboard.html')

# 家长页面
@app.route('/parent_dashboard')
def parent_dashboard():
    return render_template('parent_dashboard.html')

if __name__ == '__main__':
    app.run(debug=True)
